package rsee.com;

//import .Settings;

import ezeye.device.EyeDeviceManager;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class EyeSetting {
	private SharedPreferences mSetting = null;

	private static String shareFile = "sharefile";

	private static String SET_USERNAME = "username";
	private static String SET_PASSWORLD = "passworld";
	private static String SET_SERVER = "server";
	private static String SET_PORT = "port";
	private static String SET_DEFALTCHANNEL = "default_channel";
	private static String SET_RECORDNAME = "recordname";
	private static String SET_TOTALCOUNT = "totalcount";
    public static String ALARM_OPEN = "alarm_open";
    public static String ALARM_COUNT = "alarm_count";
	private static String SET_RECORDID = "record_id";
	public static String DEVICEINFO = "deviceinfo";
	private static String YEAR = "year";
	private static String MONTH = "month";
	private static String DAY = "day";
	private static String BANBEN = "banben";
	private static String TIME = "time";

	public EyeSetting(Context context) {
		mSetting = context.getSharedPreferences(shareFile, Context.MODE_APPEND);
	}

	public String getTime() {
		String result = mSetting.getString(TIME, "");
		return result;
	}

	public String getBanben() {
		String result = mSetting.getString(BANBEN, "0.0.0.0");
		return result;
	}
	
	public void setTimeAndBanben(String time, String banben) {
		Editor editor = mSetting.edit();
		editor.putString(TIME, time);
		editor.putString(BANBEN, banben);
		editor.commit();
	}
	
	public void setDeviceInfo(String recordName) {
	    EyeDeviceManager.setToSettings(mSetting, recordName);
	}
	
    public SourceIdent getSettingIdent() {
        SourceIdent ident = getSettingIdentImpl((byte) 0, true);
        return ident;
    }

    public SourceIdent getSettingIdent(byte chanIndex) {
        SourceIdent ident = getSettingIdentImpl(chanIndex, false);
        return ident;
    }

    private SourceIdent getSettingIdentImpl(byte chanIndex, boolean useDefault) {
        String record = mSetting.getString(SET_RECORDNAME, "");
        byte channel = chanIndex;
        if (useDefault)
            channel = (byte) mSetting.getInt(SET_DEFALTCHANNEL, 0);

        SourceIdent ident = SourceIdent.createSourceIdent(record, channel);
        if (null != ident)
            ident.setRecordName(record);
        return ident;
    }
}
